improve how RGBA buffers are copied to n_component
authorØyvind Kolås <pippin@gimp.org>
Mon, 28 Apr 2014 13:34:51 +0000 (15:34 +0200)
committerØyvind Kolås <pippin@gimp.org>
Mon, 28 Apr 2014 13:53:47 +0000 (15:53 +0200)
babl/babl-fish-reference.c

index 05172da8f0f5ca2be7015f6baca76b079f55108e..6d0f270c6fe500f05af995d9d47b8a1627f2cc38 100644 (file)
@@ -270,6 +270,60 @@ ncomponent_convert_from_double (BablFormat *destination_fmt,
 }
 
 
+static int
+process_same_model2 (const Babl  *babl,
+                    const char *source,
+                    char       *destination,
+                    long        n)
+{
+  void *double_buf;
+
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+
+  double_buf = babl_malloc (sizeof (double) * n *
+                            MAX (BABL (babl->fish.source)->format.model->components,
+                                 BABL (babl->fish.source)->format.components));
+#undef MAX
+
+  if (1)
+    {
+      /* FIXME: should recursively invoke babl and look up an appropriate fish
+       * for the conversion and multiply n by the number of components.
+       */
+      ncomponent_convert_to_double (
+        (BablFormat *) BABL (babl->fish.source),
+        (char *) source,
+        double_buf,
+        n
+      );
+
+      ncomponent_convert_from_double (
+        (BablFormat *) BABL (babl->fish.destination),
+        double_buf,
+        (char *) destination,
+        n
+      );
+    }
+  else
+    {
+      convert_to_double (
+        (BablFormat *) BABL (babl->fish.source),
+        (char *) source,
+        double_buf,
+        n
+      );
+
+      convert_from_double (
+        (BablFormat *) BABL (babl->fish.destination),
+        double_buf,
+        (char *) destination,
+        n
+      );
+    }
+  babl_free (double_buf);
+  return 0;
+}
+
 
 static int
 process_same_model (const Babl  *babl,
@@ -347,6 +401,13 @@ babl_fish_reference_process (const Babl *babl,
       BABL (babl->fish.destination)->format.model)
     return process_same_model (babl, source, destination, n);
 
+  if (babl_format_is_format_n (BABL (babl->fish.destination)))
+  {
+    return process_same_model2 (babl, source, destination, n);
+  }
+  
+
+
   source_double_buf = babl_malloc (sizeof (double) * n *
                                    BABL (babl->fish.source)->format.model->components);
   rgba_double_buf        = babl_malloc (sizeof (double) * n * 4);